var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
    })(e, t);
}, function(e, t) {
    function n() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (n.prototype = t.prototype, 
    new n());
}), a = this && this.__decorate || function(e, t, o, n) {
    var r, i = arguments.length, a = i < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, o) : n;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(e, t, o, n); else for (var c = e.length - 1; 0 <= c; c--) (r = e[c]) && (a = (i < 3 ? r(a) : 3 < i ? r(t, o, a) : r(t, o)) || a);
    return 3 < i && a && Object.defineProperty(t, o, a), a;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("GameManager"), s = e("GameItem"), c = e("AudioManager"), l = e("Global"), d = e("GameConfig"), u = cc._decorator, p = u.ccclass, h = (u.property, 
function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.sprites = [], e.skeletons = [], e;
    }
    return i(e, t), e.prototype.onEnable = function() {
        cc.systemEvent.on("game_air", this.doEffect, this);
    }, e.prototype.onDisable = function() {
        cc.systemEvent.off("game_air");
    }, e.prototype.doDestroy = function() {
        var t = r.default.getInstance().gameView;
        t ? this.skeletons.forEach(function(e) {
            return t.removeSkeleton(e.node);
        }) : 0 < this.skeletons.length && this.skeletons.forEach(function(e) {
            e.node && e.node.destroy();
        });
    }, e.prototype.start = function() {}, e.prototype.doEffect = function() {
        var e, a, o, f = this, u = r.default.getInstance().gameView;
        u && (!(e = u.astar.getGird(u.curPlayer.node.getPosition())) || (a = u.checkEmptyGird(e.x - d.GC.bufferConfig.rule.gird, e.y - d.GC.bufferConfig.rule.gird, e.x + d.GC.bufferConfig.rule.gird, e.y + d.GC.bufferConfig.rule.gird)) && (o = cc.v2(80 * a.x + 40 - u.map.width / 2, 80 * a.y + 40 - u.map.height / 2), 
        u.appendSprite({
            url: "image/ui/空投飞机@2x",
            root: u.layout,
            pos: o.add(this.getPos(2e3))
        }).then(function(e) {
            var t;
            e && (c.default.getInstance().playAudio("飞机飞过音效", .5), (t = e).node.scale = 1.5, 
            t.node.angle = 0, cc.tween(t.node).to(3, {
                position: o
            }).call(function() {
                var n, i;
                u && (n = f.checkBufferConfig(), i = 0, f.schedule(function() {
                    var e, t, o;
                    i < n.length && (e = n[i], (t = u.checkEmptyGird(a.x - d.GC.gameAirRange, a.y - d.GC.gameAirRange, a.x + d.GC.gameAirRange, a.y + d.GC.gameAirRange)) && ((o = u.getItem()).parent = u.layout, 
                    o.zIndex = 2 * -t.y, o.setPosition(t.scale(cc.v2(80, 80)).add(cc.v2((80 - u.map.width) / 2, (80 - u.map.height) / 2))), 
                    o.getComponent(s.default).init(l.ItemType.BUFFER, e), r.default.getInstance().gameView.items.push(o.getComponent(s.default)))), 
                    i++;
                }, GA.rand(1, 2), n.length - 1, 0));
            }).to(3, {
                position: o.add(f.getPos(-2e3))
            }).call(function() {
                u ? u.removeSprite(t.node) : t.node && t.node.destroy();
            }).start());
        })));
    }, e.prototype.getPos = function(e, t) {
        return void 0 === t && (t = 130), cc.v2(Math.sin(cc.misc.degreesToRadians(t)) * e, Math.cos(cc.misc.degreesToRadians(t)) * e);
    }, e.prototype.checkBufferConfig = function() {
        for (var e = 0, t = 0; e < d.GC.bufferConfig.rule.scale.length && d.GC.bufferConfig.rule.scale[e] > t; ) t = 100 * Math.random(), 
        e++;
        var o = [], n = 0, r = [];
        d.GC.bufferConfig.buffer.forEach(function(e) {
            return n += e.weight;
        }), d.GC.bufferConfig.buffer.forEach(function(e) {
            0 < r.length ? r.push(r[r.length - 1] + e.weight / n) : r.push(e.weight / n);
        });
        for (var i = 0; i < e; i++) {
            for (var t = Math.random(), a = 0; a < r.length - 1 && r[a] < t; ) a++;
            o.push(d.GC.bufferConfig.buffer[a]);
        }
        return o;
    }, a([ p ], e);
}(cc.Component));

n.default = h;